// pages/estatecontent/estateInfo/estateInfo.js
var sayname = require("../../../template/template.js");
var WxParse = require('../../../wxParse/wxParse.js');
var menuEvent = require("../../../utils/menuEvent.js").menuEvent;

var time = 0;
var touchDot = 0;//触摸时的原点
var interval = "";
var flag_hd = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasLoadImg: false,
    indicatorDots: false,
    autoplay: false,
    KeyId: "",
    EstateType: "",
    current: 0,
    _EvPic: [{ EvPic1: null }, { EvPic2: null }, { EvPic3: null }, { EvPic4: null }, { EvPic5: null }, { EvPic6: null }, { EvPic7: null }, { EvPic8: null }, { EvPic9: null }, { EvPic10: null }],
    EstateLine: [],
    acEstateLineArray: [{ EstateLine1: null }, { EstateLine2: null }, { EstateLine3: null }, { EstateLine4: null }, { EstateLine5: null }, { EstateLine6: null }, { EstateLine7: null }, { EstateLine8: null }, { EstateLine9: null }, { EstateLine10: null }],
    _EvfilePic: [],

    menuarray: '',// [{ message: "横琴定位" }, { message: "横琴交通" }, { message: "横琴规划" }, { message: "横琴经济" }],
    menuitem: {
      showmenu1: true,
      showmenu2: true,
      showmenu3: true,
      showmenu4: true,
      showmenu5: true

    },

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    var that = this;
    that.setData({
      EstateType: options.EstateType,
      KeyId: options.KeyId,
      current:0 /*(parseInt(options.EstateType)-1) */,
    })
    var ssArray = [], ssPic = [], ssfilePic = [];
    wx.getStorage({
      key: 'EstateInfoLine',
      success: function (res) {
       
        var _ELine = res.data.filter(function (x) { return x.Type != "0" });//根据类型筛选
        var _Einfo = res.data.filter(function (x) { return x.Type == options.EstateType });//根据类型筛选

        for (var j = 0; j < _ELine.length; j++) {
          ssPic.push(_ELine[j].EstatePicLine)
         
                ssArray.push(_ELine[j]);
        

          for (var i = 0; i < _ELine[j].EstatePicLine.length; i++) {
            _ELine[j].EstatePicLine[i].PicPath = _ELine[j].EstatePicLine[i].PicPath + '?w=500'
          }
        }

      
        that.setData({
          _EvPic: ssPic,
          acEstateLineArray: ssArray  
          //   EstatePicLine: _Einfo.EstatePicLine//项目介绍的图片
        })
      for (var s = 0; s < that.data.acEstateLineArray.length; s++) {   
         WxParse.wxParse('acEstateLine' + (s + 1), 'html', that.data.acEstateLineArray[s].Memo, that, 5);
        } 
    
      },

    })
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  }
  ,

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  touchstart: function () {
   console.log("滚动");
    var that = this;
    var hasLoadImg = that.data.hasLoadImg;
    if (hasLoadImg == false) {
     console.log(that);
      setHtmlImgShow(that, that.data.imgList);
      that.setData({
        hasLoadImg: true
      });
    }
  }
  ,
  change: function (e) {
   // console.log(e);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
          title: '中原地产',
         /* desc: '最具人气的小程序开发联盟!',*/
          path: '/pages/estatecontent/content?KeyId=' + that.data.KeyId
       }
  },
  onPageScroll: function (e) {

  },
  templateEvent: function (e) {
    var that = this;
    sayname.GetMemu(that, e.currentTarget.dataset.event);//加载菜单数据
    menuEvent[e.currentTarget.dataset.event](e, that);//绑定二级菜单事件

  },

  BigImg: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    var Munm = 0;
    if (Munm != '')
      Munm = that.data.options.EstateType - 1

   
    if (thisimg != '')
      thisimg = thisimg.replace('?w=200', '');


    var thisimgArray = [];
    if (that.data._EvPic[Munm] != null) {
      for (var i = 0; i < that.data._EvPic[Munm].length; i++) {
       /* console.log(that.data._EvPic[Munm][i].PicPath)*/
        thisimgArray.push(that.data._EvPic[Munm][i].PicPath.replace('?w=200', ''))
      }
    }

    wx.previewImage({
      current: thisimg, // 当前显示图片的http链接
      urls: thisimgArray // 需要预览的图片http链接列表
    })
  },
  BigImg1: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[1])
   /* var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    var Munm = 1;
    console.log(that.data.current + '8888888888888888888')
    if (thisimg != '')
      thisimg = thisimg.replace('?w=200', '');
    var thisimgArray = [];
    if (that.data._EvPic[Munm] != null) {
      for (var i = 0; i < that.data._EvPic[Munm].length; i++) {
        console.log(that.data._EvPic[Munm][i].PicPath)
        thisimgArray.push(that.data._EvPic[Munm][i].PicPath.replace('?w=200', ''))
      }
    }
    wx.previewImage({
      current: thisimg, // 当前显示图片的http链接
      urls: thisimgArray // 需要预览的图片http链接列表
    })*/
  },
  BigImg2: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[2])
  },
  BigImg3: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[3])
  },
  BigImg4: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[4])
  },
  BigImg5: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[5])
  },
  BigImg6: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[6])
  },
  BigImg7: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[7])
  },
  BigImg8: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[8])
  },
  BigImg9: function (e) {
    var that = this;
    var thisimg = e.currentTarget.dataset.imgsrc;
    SetBiGimg(that, thisimg, that.data._EvPic[8])
  }

})



function SetBiGimg(that, thisimg, _EvPic) {

  if (thisimg != '')
    thisimg = thisimg.replace('?w=200', '');
  var thisimgArray = [];
  if (_EvPic != null) {
    for (var i = 0; i < _EvPic.length; i++) {
      console.log(_EvPic[i].PicPath)
      thisimgArray.push(_EvPic[i].PicPath.replace('?w=200', ''))
    }
  }
  wx.previewImage({
    current: thisimg, // 当前显示图片的http链接
    urls: thisimgArray // 需要预览的图片http链接列表
  })

}

/*设置图片属性*/
function setHtmlImgShow(data, dom) {
  var param = {};
  var imgArray = new Array();
  if (dom == undefined || dom == null) {
    return;
  }
  if (dom != null && dom != undefined && dom.length != undefined) {
    for (var index = 0; index < dom.length; index++) {
      imgArray.push(dom[index]);
    }
  }
  else {
    imgArray.push(dom);
  }
  for (var index = 0; index < imgArray.length; index++) {
    param[imgArray[index].nodeName + ".attr.src"] = imgArray[index].attr.dataSrc;
    //console.log(param);
    data.setData(param);
    param = {};
  }
}